package ads.util;

import java.io.IOException;
import java.util.Properties;

public class ServerConfig {
	private static final String SPREAD_CONFIG = "server.properties";

	private String daemonHost;
	private Integer daemonPort;
	private String privateName;
	private String groupName;
	private Integer serverPort;
	private Integer regstryPort;
	private String regstryHost;
	private String serverName;

	public static ServerConfig load() {
		Properties prop = new Properties();
		try {
			java.net.URL url = ClassLoader.getSystemResource(SPREAD_CONFIG);

			if (url == null) {
				url = Thread.currentThread().getContextClassLoader()
						.getResource(SPREAD_CONFIG);
			}
			try {
				prop.load(url.openStream());
			} catch (IOException e) {
				e.printStackTrace();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		ServerConfig config = new ServerConfig();
		config.daemonHost = prop.getProperty("spread.daemon.host");
		config.daemonPort = Integer.valueOf(prop
				.getProperty("spread.daemon.port"));
		config.privateName = prop.getProperty("spread.privatename");
		config.groupName = prop.getProperty("spread.group.name");
		config.serverPort = Integer
				.valueOf(prop.getProperty("rmi.server.port"));
		config.regstryPort = Integer.valueOf(prop
				.getProperty("rmi.regstry.port"));
		config.regstryHost = prop.getProperty("rmi.regstry.host");
		config.serverName = prop.getProperty("rmi.server.name");

		return config;
	}

	public String getDaemonHost() {
		return daemonHost;
	}

	public void setDaemonHost(String daemonHost) {
		this.daemonHost = daemonHost;
	}

	public Integer getDaemonPort() {
		return daemonPort;
	}

	public void setDaemonPort(Integer daemonPort) {
		this.daemonPort = daemonPort;
	}

	public String getPrivateName() {
		return privateName;
	}

	public void setPrivateName(String privateName) {
		this.privateName = privateName;
	}

	public String getGroupName() {
		return groupName;
	}

	public void setGroupName(String groupName) {
		this.groupName = groupName;
	}

	public Integer getServerPort() {
		return serverPort;
	}

	public void setServerPort(Integer serverPort) {
		this.serverPort = serverPort;
	}

	public Integer getRegstryPort() {
		return regstryPort;
	}

	public void setRegstryPort(Integer regstryPort) {
		this.regstryPort = regstryPort;
	}

	public String getRegstryHost() {
		return regstryHost;
	}

	public void setRegstryHost(String regstryHost) {
		this.regstryHost = regstryHost;
	}

	public String getServerName() {
		return serverName;
	}

	public void setServerName(String serverName) {
		this.serverName = serverName;
	}

}
